package com.nabi.library.contents.elements.figure
{
	import com.nabi.library.contents.elements.NabiObject;
	import com.nabi.library.contents.elements.Outline;
	import com.nabi.library.contents.elements.segment.CloseSegment;
	import com.nabi.library.contents.elements.segment.CubicSegment;
	import com.nabi.library.contents.elements.segment.MoveSegment;
	import com.nabi.library.contents.geom.ITransform;
	import com.nabi.library.contents.geom.NativeTransform;
	import com.yzi.utilitys.CoordinateConverter;
	
	import flash.geom.Point;
	
	public class Circle extends NabiObject
	{
		public function Circle($cx:Number = 0, $cy:Number = 0, $r:Number = 1)
		{
			var outline:Outline = new Outline();
			var outlineList:Vector.<Outline> = new Vector.<Outline>();
			
			var controlPoint:Point = new Point();
			outline.AddTail(new MoveSegment(Vector.<Number>([($cx + $r), $cy])));
			outline.AddTail(new CubicSegment(Vector.<Number>([($cx + $r) + 0, $cy + ($r * 0.552), ($cx + $r) + (-$r * 0.22386 * 2), $cy + $r, $cx, $cy + $r])));
			controlPoint = CoordinateConverter.PolarPoint(new Point($cx, $cy + $r), new Point(($cx + $r) + (-$r * 0.22386 * 2), $cy + $r));
			
			outline.AddTail(new CubicSegment(Vector.<Number>([controlPoint.x, controlPoint.y, ($cx - $r), ($cy + $r) + (-$r * 0.22386 * 2), ($cx - $r), $cy])));
			controlPoint = CoordinateConverter.PolarPoint(new Point(($cx - $r), $cy), new Point(($cx - $r), ($cy + $r) + (-$r * 0.22386 * 2)));
			
			outline.AddTail(new CubicSegment(Vector.<Number>([controlPoint.x, controlPoint.y, ($cx - $r) + ($r * 0.22386 * 2), ($cy - $r), $cx, ($cy - $r)])));
			controlPoint = CoordinateConverter.PolarPoint(new Point($cx, ($cy - $r)), new Point(($cx - $r) + ($r * 0.22386 * 2), ($cy - $r)));
			
			outline.AddTail(new CubicSegment(Vector.<Number>([controlPoint.x , controlPoint.y, ($cx + $r), ($cy - $r) + ($r * 0.22386 * 2), ($cx + $r), $cy])));
			outline.AddTail(new CloseSegment(Vector.<Number>([$cx + $r, $cy])));
			outline.Update();
			outlineList.push(outline);
			
			super(outlineList);
			
			var transform:ITransform = new NativeTransform(this);
			SetTransform(transform);
		}
	}
}